import 'package:oramemo/entity/device_mine_entity.dart';

import '../network/dio_client.dart';
import '../config/api_config.dart';
import '../models/api_response.dart';
import '../models/device.dart';

class DeviceRepository {
  final DioClient _client = DioClient();

  Future<ApiResponse<void>> bindDevice(Map<String,String> data) async {
    final response = await _client.request(
      path: ApiConfig.bindDevice,
      method: 'POST',
      data: data,
    );
    return ApiResponse.fromJson(response.data, null);
  }

  Future<ApiResponse<void>> unbindDevice(String deviceId) async {
    final response = await _client.request(
      path: ApiConfig.unbindDevice,
      method: 'POST',
      data: {'id': deviceId},
    );
    return ApiResponse.fromJson(response.data, null);
  }

  Future<ApiResponse<DeviceMineEntity>> getMyDevices() async {
    final response = await _client.request(
      path: ApiConfig.myDevices,
      method: 'GET',
    );
    return ApiResponse.fromJson(
      response.data,
      (data) => DeviceMineEntity.fromJson(data)
    );
  }
}